let defaultState = {
    products: [],
    exitsProducts: []
}
function typhoonReducer(state=defaultState, action){
    switch (action.type) {
        case 'add':
            return Object.assign({},state,action.data);
        case "product":
            filterProduct(state, action.data);
            return Object.assign({},state,action.data);
        case "fullscreen":
            fullscreen(state, action.data);
            return Object.assign({},state,action.data);
        case "exitFullscreen":
            exitFullscreen(state);
            return Object.assign({},state,action);
        case "carousel":
            return Object.assign({},state,action.data);
        default:
            return state;
    }
}

//tab切换过滤产品
function filterProduct(state, data){
    const { type } = data;
    const { products } = state;
    if(products && products.length > 0){
        if(type === 'all'){
            products.map(item => item.checked = false);
        }else{
            products.map(ktem => { ktem.checked = ktem.type === type ? true : false; });
        }
    }
}

//全屏展示产品
function fullscreen(state, data){
    const { index, checked } = data;
    const { products } = state;
    if(products && products.length > 0){
        products.map(item => item.checked = false);
        products[index].checked = checked;
    }
}

//退出全屏
function exitFullscreen(state){
    if(state.products && state.products.length > 0){
        state.products.map(item => item.checked = false);
    }
}

export default typhoonReducer;